package com.leozhang.portalssm.controller;


import com.leozhang.portalssm.entity.Equipmentbrand;
import com.leozhang.portalssm.entity.Equipmentstatus;
import com.leozhang.portalssm.service.EquipmentService;
import com.leozhang.portalssm.service.EquipmentStatusService;
import com.leozhang.portalssm.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@RequestMapping("/equipmentstatus")
@Controller
public class EquipmentStatusController {
    @Autowired
    private EquipmentStatusService equipmentstatusService;

    @RequestMapping("/list")
    public String equipmentstatuslist(){
        return "type/equipmentstatus/list";
    }

    @RequestMapping("/list/page")
    @ResponseBody
    public Result equipmentstatusListPage(@RequestParam(value = "pno",defaultValue = "1")int pno,
                                         @RequestParam(value = "psize",defaultValue ="10")int psize,
                                         @RequestParam(value="statusName",defaultValue = "")String statusName,
                                         @RequestParam(value="sortField",defaultValue = "")String sortField,
                                         @RequestParam(value="sortType",defaultValue = "")String sortType)
    {
        System.out.println("我是测试代码1"+equipmentstatusService.getListForPage(pno,psize,statusName,sortField,sortType));
        return equipmentstatusService.getListForPage(pno,psize,statusName,sortField,sortType);
    }



    @RequestMapping("/add/page")
    public String Toequipmentstatuspage(){
        return "type/equipmentstatus/add";
    }

    @RequestMapping("/add")
    public String addequipmentStatus(Equipmentstatus equipmentstatus){
        equipmentstatusService.insertequipmentstatus(equipmentstatus);
        return "redirect:/equipmentstatus/list";
    }

    @RequestMapping("/edit/page")
    public String editpage(Long id, Model model){
        Equipmentstatus equipmentstatus = equipmentstatusService.selectequipmentStatusById(id);
        //这里的key命名为formData是为了写别的模块可以快速的改
        model.addAttribute("formData",equipmentstatus);
        return "/type/equipmentstatus/edit";
    }

    @RequestMapping("/edit")
    public String editequipmentstatus(Equipmentstatus equipmentstatus){
        equipmentstatusService.updateEquipmentStatus(equipmentstatus);
        return "type/equipmentstatus/list";
    }

    @RequestMapping("/delete")
    public String statusDelete(Long id){
        equipmentstatusService.deleteequipmentstatusById(id);
        return "redirect:/equipmentstatus/list";
    }
}
